package feizhu_0019;

import Ep02_LinkedList.ListNode;

import java.util.List;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/6/20 22:27
 * 说明： 删除倒数第n个链表元素
 */

public class Mine {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummyNode = new ListNode(0, head);
        ListNode pre = dummyNode;
        ListNode cur = pre;
        while (n >= 0) {
            cur = cur.next;
            n--;
        }
        while (cur != null) {
            pre = pre.next;
            cur = cur.next;
        }
        pre.next = pre.next.next;
        return dummyNode.next;
    }
}
